package com.wang.tool.util;

import java.io.Serializable;

/**
 * @author dexwang
 */
public class PageParam implements Serializable {
    private static final long serialVersionUID = 1L;


    private Integer pageNum;
    private Integer pageSize;


    public static PageParam of(Integer pageNum, Integer pageSize) {
        PageParam pageParam = new PageParam();
        pageParam.setPageNum(pageNum);
        pageParam.setPageSize(pageSize);
        return pageParam;
    }

    public PageParam next() {
        PageParam next = new PageParam();
        next.setPageSize(this.pageSize);
        next.setPageNum(this.pageNum + 1);
        return next;
    }

    public PageParam previousOrFirst() {
        Integer page = this.pageNum==null?0:this.pageNum - 1;
        if (page < 0) {
            page = 0;
        }
        PageParam previous = new PageParam();
        previous.setPageSize(this.pageSize);
        previous.setPageNum(page);
        return previous;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    @Override
    public String toString() {
        return "PageParam{" +
                "pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                '}';
    }
}
